import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

@Injectable()
export class TranslatorService {

  defaultLanguage = 'cn';
  availablelangs: any;
  constructor(private translate: TranslateService) {
    translate.setDefaultLang(this.defaultLanguage);
    this.availablelangs = [
      { code: 'cn', text: '中文' },
      { code: 'en', text: 'English' },
      { code: 'es_AR', text: 'Spanish' }
    ];
    this.useLanguage();
  }

  useLanguage(lang: string = this.defaultLanguage) {
    this.translate.use(lang);
  }
  getAvailableLanguages() {
    return this.availablelangs;
  }

}
